#include "BDD.h"

void init(graph *g)
{

	g->root = NULL ;
}


void deleteVertex(vertex *v)
{
	if(v->low != NULL)
		deleteVertex(v->low);
	if (v->high != NULL)
		deleteVertex(v->high);
	
	free(v);
}


void deInit(graph *g)
{
	deleteVertex(g->root);
	//g->root = NULL;
}




struct vertex *insertVertex(int val, int index, char *c, int id )
{
	struct vertex *v = (struct vertex *) malloc (sizeof(struct vertex));
	v->index = index;
	v->value = val;
	v->id = id;
	v->c = (char *) malloc (sizeof(char) * strlen(c));
	strcpy(v->c, c);
	v->low = NULL;
	v->high = NULL;
	v->mark = FALSE;
	return v;
}


int size(struct vertex* v,int i, int var) 
{ 


	v->mark = !(v->mark);
	i++;
	if((v->index) <= (var-1) )			//rigtht now i am inserting value for variables manually.
	{
		if((v->mark) != (v->low->mark))
			i = size(v->low,i,var);

		if ((v->mark) != (v->high->mark))
			i = size(v->high,i,var);

	}

/*


	if (vertex==NULL )
		return(0); 
	else
    		return(size(vertex->low) + 1 + size(vertex->high)); 
*/
	return i;
}

int graphSize(graph *g, int var)
{		
	return(size(g -> root,0,var));
} 

int findVar(graph *g)
{
	
}
